package com.myblog.Utils;

import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.stream.Collectors;

public class BeanCopyUtils {
    private BeanCopyUtils(){}
    public static<V> V copyBean(Object source,Class<V> vo) {
        //创建目标对象
        V result;
       try {
           result = vo.newInstance();
           BeanUtils.copyProperties(source,result);
       }catch (Exception e){
           throw new RuntimeException();
       }
        return result;
    }

    public static<O,V> List<V> copyBeanList(List<O> list, Class<V> clazz){
      //采用流的形式读取List
        return list.stream()
              .map(o->copyBean(o,clazz))
              .collect(Collectors.toList());


    }

}
